package com.bawei.module_login.view.adapter

import android.content.Context
import android.view.View
import android.widget.ImageView
import com.bawei.module_base.net.bean.login.FindConstellationListBean
import com.bawei.module_login.R
import com.bumptech.glide.Glide
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions

import com.zhy.adapter.recyclerview.CommonAdapter
import com.zhy.adapter.recyclerview.base.ViewHolder

class ConstellationAdapter(context: Context?,
                           layoutId: Int, datas: MutableList<FindConstellationListBean>?
) : CommonAdapter<FindConstellationListBean>(context, layoutId, datas) {
    override fun convert(holder: ViewHolder?, t: FindConstellationListBean?, position: Int) {
        var flag:Boolean=false
        if (t != null) {
            holder?.getView<ImageView>(R.id.constellation_img)?.let {
                //设置图片
                Glide.with(mContext)
                    .load(if (t.selected) t.selectedPic else t.unselectedPic)
                    .apply(RequestOptions.bitmapTransform(RoundedCorners(20)))
                    .into(it)
                //所有数据重置
                holder.convertView.setOnClickListener(View.OnClickListener {
                    mDatas.forEach{
                        c->
                        c.reset()
                    }
                    //设置当前点击的为选中状态
                    t.selected=true
                    notifyDataSetChanged()
                    //存入id
                    constellationset?.open(t.selectId,true)
                })
            }
        }


    }
    interface ConstellationSet {
        fun open(id: Int,flag:Boolean)
    }

    private var constellationset: ConstellationSet? = null
    fun setConstellationSet(constellationset: ConstellationSet?) {
        this.constellationset = constellationset
    }
}
